<!DOCTYPE html>
<html>
<head>
    <title>jsBridge demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="http://static.upin158.com/cdn/jsbridge-mini.js"></script>
</head>
<body>
    <input type="button" value="Reload this page" onclick="location.reload()" />
    <hr />
    本 DEMO 是不能直接在浏览器里运行的，必须在App封包环境下使用。
    <textarea rows="15" style="width:100%;" id="log"></textarea>

    <input type="button" value="jsBridge.aliPay" id="aliPay" /> -
    <input type="button" value="jsBridge.wxPay" id="wxPay" /> -
    <input type="button" value="jsBridge.net" id="net" />

    <script>

        function log(message) {
            var log = $("#log");
            log.val(message + "\r\n----------------\r\n" + log.val());
        }

        jsBridge.ready(function () {

            log("jsBridge is ready");

            $("#aliPay").click(function () {
                //支付宝: 移动支付
                //see https://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103663&docType=1
                jsBridge.aliPay({
                    orderString: "按照这里 https://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103663&docType=1 构造的订单字符串"
                }, function (succ, text) {
                    log(succ + "\r\n" + text);
                });
            });

            $("#wxPay").click(function () {
                //微信: APP支付
                //see https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_12&index=2
                jsBridge.wxPay({
                    appid:      "wx888888888888888",
                    partnerid:  "商户号",
                    prepayid:   "预支付交易会话ID",
                    package:    "扩展字段",
                    noncestr:   "随机字符串",
                    timestamp:  "1469290298",
                    sign:       "签名"
                }, function (succ, text) {
                    log(succ + "\r\n" + text);
                });
            });

            $("#net").click(function () {
                //网络访问
                jsBridge.net({
                    url: "http://...............",
                    method: "POST",
                    params: {
                        username: "aabbcc",
                        password: "112233"
                    },
                    headers: {
                        "X-Requested-With": "XMLHttpRequest", //如 模拟ajax请求
                    },
                    indicator: true
                }, function (succ, text) {
                    log(succ + "\r\n" + text);
                });
            });
        });

    </script>

</body>
</html>
